package mao.leetcode.dp.leetcode63;

public class Solution {

    public static void main(String[] args) {
        int[][] a = {{0},{1}};
        uniquePathsWithObstacles(a);
    }
    public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
        boolean flag = true;
        int[] cur = new int[obstacleGrid[0].length];
        for (int i = 0; i < obstacleGrid[0].length; i++) {
           if (!flag ) {
               cur[i] = 0;
               continue;
           }
           if (obstacleGrid[0][i] == 1){
               cur[i] = 0;
               flag = false;
               continue;
           }
           cur[i]=1;
        }
        for (int i = 1; i < obstacleGrid.length; i++) {
            if (obstacleGrid[i][0] == 1) cur[0]=0;
            for (int j = 1; j < obstacleGrid[0].length; j++) {
                if (obstacleGrid[i][j] == 1) cur[j]=0;
                else cur[j]+=cur[j-1];
            }
        }
        return cur[obstacleGrid[0].length-1];
    }
}
